package com.qezhhnjy.mall.ware.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.ware.PurchaseDetail;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.ware.service.PurchaseDetailService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "接口")
@Slf4j
@RequestMapping("/purchase-detail")
public class PurchaseDetailController {
    @Resource
    private PurchaseDetailService purchaseDetailService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取信息")
    public BaseResult<PurchaseDetail> get(Long id) {
        PurchaseDetail purchaseDetail = purchaseDetailService.getById(id);
        return BaseResult.success(purchaseDetail);
    }

    @PostMapping("/save")
    @Operation(summary = "新增信息")
    public BaseResult<PurchaseDetail> save(@RequestBody PurchaseDetail purchaseDetail) {
        purchaseDetailService.save(purchaseDetail);
        return BaseResult.success(purchaseDetail);
    }

    @PutMapping("/update")
    @Operation(summary = "更新信息")
    public BaseResult<PurchaseDetail> update(@RequestBody PurchaseDetail purchaseDetail) {
        purchaseDetailService.updateById(purchaseDetail);
        return BaseResult.success(purchaseDetail);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取信息")
    public BaseResult<Page<PurchaseDetail>> page(@RequestBody Page<PurchaseDetail> page) {
        purchaseDetailService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除信息")
    public BaseResult<Long> delete(Long id) {
        purchaseDetailService.removeById(id);
        return BaseResult.success(id);
    }
}

